#include "stdio.h"
#include "stdlib.h"
#include "string.h"

#include <ctype.h>


/*
1 编写一个业务函数，实现字符串（前后各有三个空格，单词前后也均有空格）
	"   i am student, you are teacher   " ，
	各个单词首字符大写，结果如下"   i am student,  you are teacher   " ，
	要求1：实现所有接口  70
	要求2：写出测试程序  30
	*/


int GetString(const char *str1 /*in*/, char *str2 /*in*/)
{
	int ret = 0;
	char *p1 = NULL, *p2 = NULL;
	int len = 0, i = 0;

	if (str1 == NULL || str2==NULL )
	{
		ret = -1;
		return ret;
	}
	len = strlen(str1);

	//
	strcpy(str2, str1);

	//初始化循环环境
	p1 = str2 +1 ;
	p2 = str2;
	for (i=0; i<len && (*p1!= NULL) ; i++)
	{
		if  (isalpha(*p1) && isspace(*p2))
		{
			*p1 = *p1 - 32;
		}

		//打造循环条件
		p2 = p1;
		p1 ++;
	}

	return ret;
}



int main()
{
	int ret = 0;
	const char *str1 = "     i am student, you are teacher   ";
	char buf[1024] = {0};

	ret = GetString(str1 /*in*/, buf /*in*/);
	if (ret != 0)
	{
		printf("func GetString() err:%d \n", ret);
		return ret;
	}
	printf("buf:%s \n", buf);

	return 0;
}
